package com.webvihar.access2db.model;

public class TableField {
	public String fieldName;
	public String type;
	public String length;
	public boolean zerofill;
	public boolean unsigned;
	public boolean allownull;
	public String defaultValue;
	public String collation;
	public String comment;

	public TableField(String fieldName, String type, String length, boolean zerofill, boolean unsigned, boolean allownull, String defaultValue, String collation, String comment) {
		this.fieldName = fieldName;
		this.type = type;
		this.length = length;
		this.zerofill = zerofill;
		this.unsigned = unsigned;
		this.allownull = allownull;
		this.defaultValue = defaultValue;
		this.collation = collation;
		this.comment = comment;
	}

	public boolean isEquals(TableField f1) {
		if(		f1 != null && 
				areBothEqual(f1.fieldName, fieldName) &&
				areBothEqual(f1.length, length) && 
				f1.zerofill == zerofill && 
				f1.unsigned == unsigned && 
				f1.allownull == allownull &&
				areBothEqual(f1.defaultValue, defaultValue) &&
				areBothEqual(f1.collation, collation) &&
				areBothEqual(f1.comment, comment)) {
			return true;
		} else {
			return false;
		}
	}
	
	private boolean areBothEqual(String s1, String s2) {
		if(s1 == null && s2 == null) {
			return true;
		} else if(s1 == null && s2 == null) {
			return false;
		} else if(s1.equals(s2)) {
			return true;
		} else {
			return false;
		}
	}
}
